package com.lwq.view;

import java.awt.BorderLayout;
import java.awt.Choice;
import java.awt.Component;
import java.awt.Frame;
import java.awt.Label;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.text.BadLocationException;
import javax.swing.text.DefaultStyledDocument;
import javax.swing.text.StyledDocument;


public class CreateMemberDialog extends Frame
{
	private JPanel mSouthPanel = null;
	private JScrollPane mCenterPanel = null;
	private JButton mOkBtn = null;
	private BoxLayout boxLayout = null;
	
	private GetDataListener mListener = null;
	private JTextPane mJTextPane = null;
	private StyledDocument document = null;

	public CreateMemberDialog(String lable,GetDataListener listener){
		super(lable);
		mListener = listener;
		setLayout(new BorderLayout());
		setEnabled(true);
		setVisible(true);
		setBounds(200, 200, 600, 300);
		mJTextPane = new JTextPane();
		document = mJTextPane.getStyledDocument();
		
		mSouthPanel = new JPanel();
		mSouthPanel.setEnabled(true);
		mSouthPanel.setVisible(true);
		
		
		
		mCenterPanel = new JScrollPane(mJTextPane);
		mCenterPanel.setEnabled(true);
		mCenterPanel.setVisible(true);
//		mSouthPanel.setBorder(new MatteBorder(2, 0, 0, 0, Color.lightGray));
		add(mCenterPanel,"Center");
		add(mSouthPanel,"South");
		addWindowListener(new WindowAdapter()
		{
			public void windowClosing(WindowEvent evt)
			{
				CreateMemberDialog.this.setVisible(false); 
				CreateMemberDialog.this.dispose(); 
			}
		});
		mOkBtn = new JButton("ok");
		mOkBtn.setVisible(true);

		mSouthPanel.add(mOkBtn);
		addContent();
		setEvent();
	}
	
	private void addContent(){
	}
	
	
	private void setEvent(){
		mOkBtn.addActionListener(new ActionListener()
		{
			@Override
			public void actionPerformed(ActionEvent arg0)
			{
				if(mListener != null){
					mListener.getDate(documentGetText());
				}
				CreateMemberDialog.this.setVisible(false); 
				CreateMemberDialog.this.dispose();
			}
		});
	}
	
	private void documentSetText(String text) {
		document = new DefaultStyledDocument();
		mJTextPane.setStyledDocument(document);
		try {
			document.insertString(document.getLength(), text + "\n", null);
		} catch (BadLocationException e) {
			e.printStackTrace();
		}
		mJTextPane.setCaretPosition(mJTextPane.getDocument().getLength());
	}
	private void documentInsertText(String text) {
		try {
			document.insertString(document.getLength(), text + "\n", null);
		} catch (BadLocationException e) {
			e.printStackTrace();
		}
		mJTextPane.setCaretPosition(mJTextPane.getDocument().getLength());
	}
	
	private String documentGetText() {
		if(document != null){
			try {
				return document.getText(0, document.getLength());
			} catch (BadLocationException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return null;
	}
	
	public interface GetDataListener{
		public void getDate(String data);
	}
}
